<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/lib/theme-chalk/index.css" />
    <!--<link rel="stylesheet" href="../../styles/common.css" />-->
    <link rel="stylesheet" href="../../styles/page.css" />
</head>
<body>
<div class="addBrand-container" id="admin-add-app">
    <div class="container">
        <el-form ref="ruleForm" :model="ruleForm" :inline="false" label-width="180px" class="demo-ruleForm">
            <div class="base">
                <el-form-item label="姓名">
                    <el-input v-model="ruleForm.name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </div>
            <el-form-item label="目标账户">
                <el-select v-model="ruleForm.accountName" placeholder="请选择账户">
                    <el-option v-for="item in accountNames" :key="item" :label="item" :value="item">{{item}}</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="缴费金额">
                <el-input v-model="ruleForm.count" placeholder="请输入金额"></el-input>
            </el-form-item>
            <el-form-item label="支付方式">
                <el-input v-model="ruleForm.payment" placeholder="请输入支付方式"></el-input>
            </el-form-item>
            <div class="subBox address">
                <el-form-item>
                    <el-button  @click="goBack()">取消</el-button>
                    <el-button type="primary" @click="pay('ruleForm', false)">缴费</el-button>
                </el-form-item>
            </div>
        </el-form>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/lib/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/student.js"></script>
<script src="../../api/account.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script>
    new Vue({
        el: '#admin-add-app',
        data() {
            return {
                id: '',
                actionType: '',
                accountNames: ['aaa','ccc'],
                channelNames: ['bbb','ccc'],
                ruleForm: {
                    studentName:'',
                    studentId:'',
                    name: '',
                    sid: '',
                    payment:'',
                    count:'',
                    accountName:''
                },
            }
        },

        created() {
            /*获取参数id*/
            this.id = requestUrlParam('id');//从网址上解析参数
            if (this.id) {
                this.init()
            }
        },
        mounted() {
        },
        methods: {
            async init () {
                //发起一个异步请求，获取用户信息
                queryStudentById(this.id).then(res => {
                    // console.log(res);
                    if (String(res.code) === '1') {
                        // console.log(res.data);
                        this.ruleForm = res.data;
                        // this.ruleForm.password = ''
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                })
                getAllAccountName().then(res=>{
                    this.accountNames = res.data
                    console.log(res.data)
                })
            },
            pay (formName, st) {
                var _this = this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.ruleForm.studentName = this.ruleForm.name
                        this.ruleForm.studentId = this.ruleForm.id
                        const params = {
                            ...this.ruleForm,
                        };
                        accountPay(params).then(res => {
                            if (res.code === 1) {
                                this.$message.success('缴费操作成功！');
                                setTimeout(function (){
                                    _this.goBack()
                                },1000);
                            } else {
                                this.$message.error(res.msg || '操作失败')
                            }
                        }).catch(err => {
                            this.$message.error('请求出错了：' + err)
                        })
                        console.log(params)
                    } else {
                        console.log('error submit!!');
                        return false
                    }
                })
            },
            goBack(){
                window.parent.menuHandle({
                    id: '1',
                    url: '/back/page/stuFlow/list.html',
                    name: '待缴费学生'
                },false)
            }
        }
    })
</script>
</body>
</html>